<!doctype html>
<html>

<head>
	<title></title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<link rel="stylesheet" href="../res/css/weui.css" />
	<link rel="stylesheet" href="../res/css/weuix.css" />
	<link rel="stylesheet" href="../res/css/common.css">
	<script src="../res/js/zepto.min.js"></script>
	<script src="../res/js/zepto.weui.js"></script>
	<script src="../res/js/common.js?v=2"></script>
	<script>
		var doctor_name = getQst("doctor_name");
		var haveFee = 0,
			haveFeeDoctorName = '',
			haveFeeLogType = 0,
			h5token = '',
			userJson = '',
			userid = '',
			usertype = '';
		var departmentList;
		var historyList = [];
		var timmer ;

		function showDoctor() {
			userJson = getUserInfo();
			h5token = userJson.h5Token;
			userid = userJson.id;
			usertype = userJson.type;
			var paramJson = {
				"current": 1,
				// "departmentId": 0,
				"parametn": doctor_name,
				"size": 20
			}
			newAjaxPost("/h5/doctorInfo/getHomeDoctorList", paramJson, showDoctorOk);
			return false;
		};

		function showDoctorOk(jsonInfo) {
			var doctorListData = '';
			var doctorListData2 = '';
			var doctNums;
			var data;
			var userJson = getUserInfo();

			data = jsonInfo.data.list;
			if (data.length > 0) {
				doctNums = data.length;
				for (var i = 0; i < data.length; i++) {
					if (data[i].isOnline == 1) { //是否在线  0否  1是
						if (doctNums != 0) {
							doctorListData += '<div class="expertlist_map" >';
							doctorListData += '<div class="expertlist_map_top to_detail" num="0" id="' + data[i].id +
								'" >';
							doctorListData += '<div class="expertlist_map_img"> <img src="' + data[i].doctorHeadImg +
								'" /> </div>';
							doctorListData += '<div class="doctor_info">';
							doctorListData += '<div class="doctor_name">' + data[i].trueName + '<span>' + data[i]
								.doctorJobTitle + '</span>   <span style="padding:5px 5px">' + data[i].departmentName +
								'</span><span class="isOnline" style="padding:5px 5px">在线</span></div>';
							doctorListData += '<div class="age">从业年限 <span>' + data[i].workAge + '年</span> 　年龄 <span>' +
								data[i].doctorAge + '岁</span></div>';
							doctorListData += '</div>';
							doctorListData += '</div>';
							doctorListData +=
								'<div style="word-break:break-all" class="brief_introduction uni-ellipsis-2 to_detail" num="0" id="' +
								data[i].id + '">' + data[i].doctorSynopsis + '</div>';
							doctorListData +=
								'<div class="view_felx home_icon_img" style="display:flex;-ms-flex-align: center;justify-content: center;">';
							doctorListData += '<div class="advisory" id="' + data[i].id +
								'" style="border:none;text-align: center;font-weight: bold;">立即咨询</div>';
							doctorListData += '</div>';
							doctorListData += '</div>';
							doctNums--;
						}
					}
					if (data[i].isOnline == 0) {
						if (doctNums != 0) {
							doctorListData2 += '<div class="expertlist_map"  num="0" id="' + data[i].id + '">';
							doctorListData2 += '<div class="expertlist_map_top to_detail" num="0" id="' + data[i].id +
								'" >';
							doctorListData2 += '<div class="expertlist_map_img"> <img src="' + data[i].doctorHeadImg +
								'" /> </div>';
							doctorListData2 += '<div class="doctor_info">';
							doctorListData2 += '<div class="doctor_name">' + data[i].trueName + '<span>' + data[i]
								.doctorJobTitle + '</span>   <span style="padding:5px 5px">' + data[i]
								.departmentName +
								'</span><span class="noOnline" style="padding:5px 5px">离线</span></div>';
							doctorListData2 += '<div class="age">从业年限 <span>' + data[i].workAge +
								'年</span> 　年龄 <span>' + data[i].doctorAge + '岁</span></div>';
							doctorListData2 += '</div>';
							doctorListData2 += '</div>';
							doctorListData2 +=
								'<div style="word-break:break-all" class="brief_introduction uni-ellipsis-2 to_detail" num="0" id="' +
								data[i].id +
								'">' + data[i].doctorSpecialty + '</div>';
							doctorListData2 +=
								'<div class="view_felx home_icon_img" style="display:flex;-ms-flex-align: center;justify-content: center;">';
							doctorListData2 += '<div class="advisory" id="' + data[i].id +
								'" style="border:none;text-align: center;font-weight: bold;">立即咨询</div>';
							doctorListData2 += '</div>';
							doctorListData2 += '</div>';
							doctNums--;
						}
					}

				}
			}
			if (doctorListData == '' && doctorListData2 == '') {
				$(".noFind").show()
			} else {
				$('#doctorList').html(doctorListData + doctorListData2);
				$(".noFind").hide()
			}

			clearInterval(timmer)
			timmer = setTimeout(function () {
				showDoctor();
			}, 10000);

			//跳转到医生页面
			$(document).on("click", ".to_detail", function () {
				log_type = $(this).attr('num');
				doctor_id = $(this).attr('id');
				// alert(doctor_id);
				if (!isLogin()) { //判断是否登录
					$.confirm("请先登录再操作", function () {
						goPage('login.htm');
					}, function () {
						//取消操作
					});
				} else {
					var strGoUrl;
					var strGoUrl = 'doctor_home_page.htm?log_type=' + log_type + '&doctor_id=' + doctor_id;
					goPage(strGoUrl);

					goPage(strGoUrl);
				}
			});

			//查看医生值班计划
			$(document).on("click", ".schedulingBtn", function () {
				log_type = $(this).attr('num');
				doctor_id = $(this).attr('id');
				goPage('inquiry_doctor_sche.htm?doctor_id=' + doctor_id + "&rand=" + Math.random());
			});
			//医生离线提示
			$('.offline').on('click', function () {
				$.alert({
					title: '温馨提示',
					text: '当前医生离线，请选择其他医生',
					onOK: function () {
						//点击确认
					}
				});
			});
			//视频、图文问诊
			$(document).on("click", ".inquiryBtn", function () {
				log_type = $(this).attr('num');
				doctor_id = $(this).attr('id');
				doctor_name = $(this).attr('docname');
				fee_pay = $(this).attr('pay');
				if (!isLogin()) { //判断是否登录
					$.confirm("请先登录再操作", function () {
						goPage('login.htm');
					}, function () {
						//取消操作
					});
				} else {
					var strGoUrl;
					if (haveFee == 0) { //没付问诊费
						strGoUrl = 'inquiry_doctor_fee.htm?feepay=' + fee_pay + '&log_type=' + log_type +
							'&doctor_id=' + doctor_id + '&doctor_name=' + doctor_name;
						goPage(strGoUrl);
					} else { //已付问诊费
						if (haveFeeDoctorName == doctor_name && log_type == haveFeeLogType) { //已付费的那个医生
							strGoUrl = 'inquiry_doctor_patient.htm?log_type=' + log_type + '&doctor_id=' + doctor_id +
								'&h5_token=' + h5token + '&user_id=' + userid + '&user_type=' + usertype;
							goPage(strGoUrl);
						} else if (haveFeeDoctorName == doctor_name && log_type != haveFeeLogType) {
							$.alert("您购买的是该医生的另一种问诊！", function () {
								return;
							});
						} else { //不是已付费的那个医生，禁止问诊
							$.alert("本日之内您还有其他医生的问诊没结束，请先完成问诊！", function () {
								return;
							});
						}
					}
				}
			});
		}

		function newGetConsultationFee() {
			if (!isLogin()) { //判断是否登录
				// 不获取
			} else {
				newAjaxPost("/h5/wxpay/getConsultationFee", {}, newGetConsultationFeeOk);
			}
		}

		function newGetConsultationFeeOk(jsonInfo) {
			var data, time = null;
			if (jsonInfo.code == 1) {
				data = jsonInfo.data;
				if (data) {
					haveFee = 1
					haveFeeLogType = data.inquiryType;
					haveFeeDoctorName = data.trueName;
				} else {
					haveFee = 0
				}
			}
		}

		// ---------------3.30
		var openid = getQst("openid").trim();
		var orgid = getQst("orgid").trim();
		$(function () {
			// ---------------3.30
			//显示医生列表
			// showDoctor();
			$(".noFind").hide()
			newGetConsultationFee()
			//获取搜索历史
			getUserSearchLogList()

			//返回上页
			$('#btnBack').on("click", function () {
				goPage("inquiry_doctor_index.htm");
			});

			//搜索
			$("#searchInput").on('keypress', function (e) {
				var keycode = e.keyCode;
				if (keycode == '13') {
					e.preventDefault();
					//请求搜索接口 
					var docname = $("#searchInput").val();
					// console.log(docname)
					doctor_name = docname;
					if (docname == '') {

					} else {
						addUserSearchLog(docname)
						showDoctor()
					}
				}
			})
		});



		//点击取消返回
		function Cancel() {
			goPageNo(-1)
		}

		//添加搜索历史
		function addUserSearchLog(val) {
			let params = {
				"content": val
			}
			newAjaxPost("/h5/userSearch/addUserSearchLog", params, (json) => {
				console.log(json);
				getUserSearchLogList()
			});
		}

		//获取搜索历史
		function getUserSearchLogList() {
			newAjaxPost("/h5/userSearch/getUserSearchLogList", {}, getUserSearchLogListOk);
		}

		function getUserSearchLogListOk(json) {
			historyList = json.data.list
			if (historyList.length == 0) {
				$(".historyWrappar").hide()
			} else {
				$(".historyWrappar").show()
			}
			var context = ''
			console.log(historyList);
			historyList.forEach((element, index) => {
				context += `<div onclick="chooseHistory(${index})">${element.content}</div>`
			});
			$('.historyList').html(context)
		}

		//删除搜索记录
		function deleteUserSearchLog() {
			newAjaxPost("/h5/userSearch/deleteUserSearchLog", {}, (json) => {
				msgInfo(json.msg)
				$(".historyWrappar").hide()
			});
		}

		//选择聊天记录搜索
		function chooseHistory(index) {
			$("#searchInput").val(historyList[index].content);
			var docname = $("#searchInput").val();
			doctor_name = docname;
			showDoctor()
		}
	</script>
	<style>
		.fixed-top {
			border-bottom: 1px solid #e8e8e8;
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 1;
			background: #F6F6F9
		}

		.weui-cells {
			padding-bottom: 60px;
		}

		.weui-tabbar__item {
			padding: 5px 0px 10px 0px;
		}

		.Cancel {
			width: 50px;
			text-align: center;
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #757575;
		}

		.historyWrappar {
			width: 90%;
			margin: 10px 5%;
		}

		.historyWrappar .title {
			height: 22px;
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #353535 !important;
			margin: 5px 0;
			display: flex;
		}

		.historyWrappar .title span {
			display: inline-block;
			height: 22px;
			width: 30%;
			line-height: 22px;
		}

		.historyWrappar .title img {
			width: 22px;
			height: 22px;
			margin-left: 70%;
		}

		.historyList {
			display: flex;
			flex-wrap: wrap;
			justify-content: left;
			align-items: center;
		}

		.historyList div {
			width: 20%;
			height: 30px;
			margin: 5px 5px;
			line-height: 30px;
			background: #fff;
			border-radius: 34px;
			text-align: center;
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #353535
		}


		.noFind {
			width: 90%;
			margin: 10px 2.5%;
			display: block;
			text-align: center;
			overflow: hidden;
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #353535;
			background-color: #F9F8FE;
		}

		.noFind img {
			width: 198px;
			height: 158px;
			border: none;
			border-radius: 0px;
			margin: 15px;
		}
	</style>
</head>

<body ontouchstart>
	<div class="fixed-top">
		<div class="weui-btn_primary weui-header">
			<div class="weui-header-left"><a id="btnBack" class="icon icon-109 "></a></div>
			<h1 class="weui-header-title">搜索结果</h1>
		</div>
	</div>
	<!-- 搜索框 -->
	<div class="weui-search-bar weui-search-bar_focusing" id="searchBar" style="margin-top:50px">
		<form class="weui-search-bar__form" action="#">
			<div class="weui-search-bar__box">
				<i class="weui-icon-search"></i>
				<input class="weui-search-bar__input" id="searchInput" placeholder="搜索科室，医生，疾病" required=""
					type="search" autocomplete="off">
				<i class="icon icon-95" style="position: absolute;right: -13%;top: 2px;" onclick="$('#searchInput').val('')"></i>
			</div>

		</form>
		<div href="javascript:" class="Cancel" id="Cancel" onclick="Cancel()">取消</div>
	</div>
	<!-- 历史记录 -->
	<div class="historyWrappar">
		<div class="title"><span>历史记录</span><img src="../res/images/icon_delete.png" alt=""
				onclick="deleteUserSearchLog()"></div>
		<div class="historyList">
		</div>
	</div>
	<!-- 搜索结果 -->
	<div>
		<div class="weui-cells">
			<div id="doctorList" style="margin-buttom:60px">
			</div>
		</div>
		<div class="weui-cell noFind"><img src="../res/images/img_empty_state@2x.png" alt="">
			<p>抱歉，查无关于此结果的数据~</p>
		</div>
	</div>


</body>

</html>